package com.wyb.moto.common.exception;


public class Result {
	private int code = 200;
	private Object result;
	private String errorMessage = "";

	public static Result ok(Object ret) {
		Result result = new Result();
		result.setResult(ret);
		return result;
	}

	/**
	 * 内部错误
	 * 
	 * @param message
	 * @return
	 */
	public static Result Error500(String message) {
		return error(message, 500);
	}

	/**
	 * 认证失败
	 * 
	 * @param message
	 * @return
	 */
	public static Result Error401(String message) {
		return error(message, 401);
	}

	/**
	 * 找不到资源
	 * 
	 * @param message
	 * @return
	 */
	public static Result Error404(String message) {
		return error(message, 404);
	}

	private static Result error(String error, int code) {
		Result result = new Result();
		result.setResult(null);
		result.setCode(code);
		result.setErrorMessage(error);
		return result;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
}
